<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
            <tip>填写用户的真实姓名！</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="M" title="男" checked="">
            <input type="radio" name="sex" value="F" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">入职日期</label>
        <div class="layui-input-block">
            <input type="date" name="birthday" placeholder="请选择日期" lay-verify="required|date" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">年龄</label>
        <div class="layui-input-block">
            <input type="number" name="age" lay-verify="required|number" lay-reqtext="年龄不能为空" placeholder="请输入年龄" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">工资</label>
        <div class="layui-input-block">
            <input type="number" name="sal" lay-verify="required|number" lay-reqtext="工资不能为空" placeholder="请输入工资" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">部门</label>
        <div class="layui-input-block">
                <select name="deptId" lay-verify="requird" lay-reqtext="用户需要安排部门">
                    <option value="">请选择</option>
                    <option th:each="dept:${deptlist}" th:value="${dept.deptId}"><span th:text="${dept.deptName}"></span></option>
                </select>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <textarea name="address" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" id="saveBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            <button type="rest" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</div>
</body>
<script th:src="@{/layui/layui.js}" charset="utf-8"></script>
<script th:inline="javascript">
    var ctxPath = [[@{/}]];
    layui.use(['form','laydate','table'],function() {
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.$;

        //监听表单提交
        form.on('submit(saveBtn)',function (data){
            //按钮登录调整为不可用
            $("#saveBtn").attr("disabled","disabled").addClass("layui-btn-disabled")
            // 设置一个定时器，在3秒后重新启用登录按钮
            setTimeout(function() {
                $("#saveBtn").removeAttr("disabled").removeClass("layui-btn-disabled");
            }, 3000); // 3000毫秒等于3秒

            //异步请求提交数据
            var url = ctxPath + "emp/addemp"
            $.post(url,data.field,function (res){
                if(res.code == 0){
                    layer.msg('添加成功！',{icon: 6},function(){
                        parent.refreshTable()
                        var index = parent.layer.getFrameIndex (window.name);
                        parent.layer.close(index);
                     })
                }else{
                    layer.msg('添加失败！',{icon: 2,anim: 6})
                }
            })
            return false;
        })

    });
</script>
</html>